<template>
    <rx-layout>
        <div slot="left" width="220" showButton="true">
            <rx-fit>
                <rx-category-treeeditor
                    cat-key="FORM"
                    :statisticConfig="statisticConfig"
                    :edit="true"
                    @handSelect="handSelect"
                    :async="true"
                ></rx-category-treeeditor>
            </rx-fit>
        </div>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formChartComponentAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-button type="primary" v-if="!isAppDevelop && selectedRowKeys.length > 0 " icon="redo"
                                  @click="changeApp('FORM',selectedRows,'pkId','name','appId','category',changeAppId)">
                            {{i18n('list.changeApp','变更应用')}}
                        </a-button>
                        <a-button v-if="selectedRowKeys.length > 0"
                                  type="primary"
                                  icon="switcher" @click="openCategoryDialog">
                            {{$ti18('rxList.changeCategory','切换分类')}}
                        </a-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="formChartComponentEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formChartComponentDelete" :butn-icon="'delete'"
                                             :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                                <a-menu-item key="3" v-if="selectedRowKeys.length > 0"
                                             alias="formChartComponentSwitcher"
                                             @click="changeExport(exportConf)">
                                    <a-icon type="switcher"/>
                                    {{$ti18('rxList.changeExport','切换导出')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="$ti18('rxForm.name','名称') ">
                            <a-input :placeholder="$ti18('rxForm.name','名称','','input')" v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="$ti18('rxForm.rxAlias','别名') ">
                            <a-input :placeholder="$ti18('rxForm.rxAlias','别名','','input') " v-model="queryParam.Q_ALIAS__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="$ti18('rxForm.appId', '应用')" v-if="!curApp.appId">
                            <rx-search-app @change="appChange" v-model="searchApps">
                            </rx-search-app>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :bordered="isBorder"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formChartComponent/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="appId" slot-scope="{ text, record }">
                        {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
                    </span>
                    <span slot="exportApp">
                         {{ exportI18n('export.isExport','导出') }}
                        <export-app/>
                    </span>
                    <span slot="isExport" slot-scope="{ text, record }">
                        <a-tag :color="text == 1 ? 'green' : 'red'">
                            <span>{{ text == 1 ? exportI18n('export.yes','是') : exportI18n('export.no','否') }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click.stop="edit(record)">{{i18n('list.design','设计')}}</span>
                         <span @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                        <span @click="setExport(record,exportConf)">{{record.isExport == 1 ? exportI18n('export.noExport','不导出') : exportI18n('export.exported','导出')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormChartComponentApi from '@/api/form/core/formChartComponent'
import FormChartComponentEdit from './FormChartComponentEdit'
import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
import RxCategoryTreeeditor from "@/components/redxun/rx-category-treeeditor";
import changeAppJs from "@/views/modules/share/changeApp";
import {mapState} from "vuex";
import AppSearch from "@/views/modules/share/AppSearch";
import RxSearchApp from "@/views/modules/share/rx-search-app";
import exportApp from "@/views/modules/share/exportApp";
import switchExport from "@/utils/switchExport";
import ChangeCategory from "@/views/modules/share/ChangeCategory.js"
export default {
    name: 'FormChartComponentList',
    mixins: [BaseList,changeAppJs,AppSearch,switchExport,ChangeCategory],
    components: {
        RxFit,
        RxCategoryTreeeditor,
        RxSearchApp
    },
    computed: {
        ...mapState({
            //所属应用
            allApps: state => state.appSetting ? state.appSetting.allApps : {}
        }),
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.$ti18('rxForm.name','名称'), dataIndex: 'name', width: 100},
                {title: this.$ti18('rxForm.rxAlias','别名'), dataIndex: 'alias', width: 100},
                {
                    dataIndex: 'isExport',
                    slots: { title: 'exportApp' },
                    width: 60,
                    scopedSlots: {customRender: 'isExport'}
                },
                {title: this.i18n('form.dataModel','数据模型'), dataIndex: 'dataModelName', width: 100},
                {title: this.i18n('form.app','所属应用'), dataIndex: 'appId', width: 100, sortField: 'APP_ID_',scopedSlots: {customRender: 'appId'}},
                {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime',  width: 120},
                {title: this.$ti18('rxList.action','操作'), width: 80, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: FormChartComponentEdit,
            comment: this.i18n('chartCompo','图表组件'),
            fitSearch: false,
            max:true,
            statisticConfig: {
                type:"static_form",
                table:"FORM_CHART_COMPONENT t",
                field:"CATEGORY_",
                whereConf:[]
            },
            /**
             * 导出配置
             */
            exportConf:{
                Api:FormChartComponentApi,
                id:"id"
            },
            //变更分类配置
            categoryConfig:{
                Api:FormChartComponentApi,
                catKey:"FORM",
                gridRef:"table"
            }
        }
    },
    created() {
        this.isUserManager(this.$route.query.appId);
        this.needFilterAppId("isAppMenu");
        this.columns=this.removeAppColumn(this.curApp.appId,this.columns)
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "formChartComponent", key);
        },
        exportI18n(name,text,key){
            return this.$ti18(name,text,"appExport",key);
        },
        delById(ids) {
            return FormChartComponentApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormChartComponentApi.query(parameter)
        },
        handSelect(curRow) {
            this.curTree = curRow
            var treeId = curRow.treeId;
            if (treeId != "0") {
                this.queryParam.Q_CATEGORY__S_EQ = treeId;
            } else {
                delete this.queryParam.Q_CATEGORY__S_EQ;
            }
            this.loadData(this.queryParam);
        },
        changeAppId(selectedRows){
            FormChartComponentApi.saveList(selectedRows);
        },
        cancel(){
            this.resetSearch();
        }
    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

